#define PLUGIN_VERSION "2.0.1"
#pragma semicolon 1

#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

ConVar g_hCvarColor_tank, g_hCvarColor_witch, g_hCvarColor_tankstone, g_hCvarColor_infectedstone, g_hCvarColor_smokerstone, g_hCvarColor_boomerstone, g_hCvarColor_hunterstone, g_hCvarColor_spitterstone, g_hCvarColor_jockeystone, g_hCvarColor_chargerstone;
int g_iCvarColor_tank, g_iCvarColor_witch, g_iCvarColor_tankstone, g_iCvarColor_infectedstone, g_iCvarColor_smokerstone, g_iCvarColor_boomerstone, g_iCvarColor_hunterstone, g_iCvarColor_spitterstone, g_iCvarColor_jockeystone, g_iCvarColor_chargerstone;

public Plugin myinfo =  
{
	name = "l4d2_infected_glow",  
	author = "木白为柏(axyio)",   
	description = "轮廓发光",             
	version = PLUGIN_VERSION,              
	url = "https://gitee.com/sweet-and-sour-bombs"                     
}

public void OnPluginStart() 
{
	CreateConVar("l4d2_border_color_version", PLUGIN_VERSION, "插件版本.", FCVAR_NOTIFY);
	g_hCvarColor_tank	   = CreateConVar("l4d2_border_color_tank", "255 255 255", "设置坦克轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_witch	   = CreateConVar("l4d2_border_color_witch", "255 255 255", "设置女巫轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_tankstone	   = CreateConVar("l4d2_border_color_tankstone", "255 255 255", "设置坦克石头轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_infectedstone	   = CreateConVar("l4d2_border_color_infectedstone", "255 255 255", "设置小僵尸轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_smokerstone	   = CreateConVar("l4d2_border_color_smokerstone", "255 255 255", "设置舌头轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_boomerstone	   = CreateConVar("l4d2_border_color_boomerstone", "255 255 255", "设置胖子轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_hunterstone	   = CreateConVar("l4d2_border_color_hunterstone", "255 255 255", "设置猎人轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_spitterstone	   = CreateConVar("l4d2_border_color_spitterstone", "255 255 255", "设置口水轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_jockeystone	   = CreateConVar("l4d2_border_color_jockeystone", "255 255 255", "设置猴子轮廓发光颜色.", FCVAR_NOTIFY);
	g_hCvarColor_chargerstone	   = CreateConVar("l4d2_border_color_chargerstone", "255 255 255", "设置牛牛轮廓发光颜色.", FCVAR_NOTIFY);
	
	g_hCvarColor_tank.AddChangeHook(SConVardonChanged);
	g_hCvarColor_witch.AddChangeHook(SConVardonChanged);
	g_hCvarColor_tankstone.AddChangeHook(SConVardonChanged);
	g_hCvarColor_infectedstone.AddChangeHook(SConVardonChanged);
	g_hCvarColor_smokerstone.AddChangeHook(SConVardonChanged);
	g_hCvarColor_boomerstone.AddChangeHook(SConVardonChanged);	
	g_hCvarColor_hunterstone.AddChangeHook(SConVardonChanged);
	g_hCvarColor_spitterstone.AddChangeHook(SConVardonChanged);
	g_hCvarColor_jockeystone.AddChangeHook(SConVardonChanged);	
	g_hCvarColor_chargerstone.AddChangeHook(SConVardonChanged);	

	//AutoExecConfig(true, "l4d2_infected_glow");
}

public void OnMapStart()
{	
	init();
}

public void SConVardonChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
	init();
}

void init()
{
	char sColorTank[1024];
	g_hCvarColor_tank.GetString(sColorTank, sizeof(sColorTank));
	g_iCvarColor_tank = GetColor(sColorTank);

	char sColorWitch[1024];
	g_hCvarColor_witch.GetString(sColorWitch, sizeof(sColorWitch));
	g_iCvarColor_witch = GetColor(sColorWitch);

	char sColorTankstone[1024];
	g_hCvarColor_tankstone.GetString(sColorTankstone, sizeof(sColorTankstone));
	g_iCvarColor_tankstone = GetColor(sColorTankstone);
	
	char sColorInfectedstone[1024];   //小僵尸
	g_hCvarColor_infectedstone.GetString(sColorInfectedstone, sizeof(sColorInfectedstone));
	g_iCvarColor_infectedstone = GetColor(sColorInfectedstone);

	char sColorsmokerstone[1024];   //舌头
	g_hCvarColor_smokerstone.GetString(sColorsmokerstone, sizeof(sColorsmokerstone));
	g_iCvarColor_smokerstone = GetColor(sColorsmokerstone);	

	char sColorboomerstone[1024];   //胖子
	g_hCvarColor_boomerstone.GetString(sColorboomerstone, sizeof(sColorboomerstone));
	g_iCvarColor_boomerstone = GetColor(sColorboomerstone);

	char sColorhunterstone[1024];   //猎人
	g_hCvarColor_hunterstone.GetString(sColorhunterstone, sizeof(sColorhunterstone));
	g_iCvarColor_hunterstone = GetColor(sColorhunterstone);

	char sColorspitterstone[1024];   //口水
	g_hCvarColor_spitterstone.GetString(sColorspitterstone, sizeof(sColorspitterstone));
	g_iCvarColor_spitterstone = GetColor(sColorspitterstone);

	char sColorjockeystone[1024];   //猴子
	g_hCvarColor_jockeystone.GetString(sColorjockeystone, sizeof(sColorjockeystone));
	g_iCvarColor_jockeystone = GetColor(sColorjockeystone);

	char sColorchargerstone[1024];   //牛牛
	g_hCvarColor_chargerstone.GetString(sColorchargerstone, sizeof(sColorchargerstone));
	g_iCvarColor_chargerstone = GetColor(sColorchargerstone);		
}

int GetColor(char[] sTemp)
{
	if( strcmp(sTemp, "") == 0 )
		return 0;

	char sColors[3][4];
	int color = ExplodeString(sTemp, " ", sColors, 3, 4);

	if( color != 3 )
		return 0;

	color = StringToInt(sColors[0]);
	color += 256 * StringToInt(sColors[1]);
	color += 65536 * StringToInt(sColors[2]);

	return color;
}

public void OnEntityCreated(int entity, const char[] classname)
{
	
	if(StrEqual(classname, "tank", true))
	{
		if(g_iCvarColor_tank > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0);
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_tank);
		}	
	}

	
	if(StrEqual(classname, "witch", true))
	{
		if(g_iCvarColor_witch > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0);
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_witch);
		}
	}

	if(StrEqual(classname, "tank_rock", true))
	{
		if(g_iCvarColor_tankstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0);
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_tankstone);
		}
	}
	if(StrEqual(classname, "infected", true)) //小僵尸
	{
		if(g_iCvarColor_infectedstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_infectedstone);
		}
	}
	if(StrEqual(classname, "smoker", true)) //舌头
	{
		if(g_iCvarColor_smokerstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_smokerstone);
		}
	}	
	if(StrEqual(classname, "boomer", true)) //胖子
	{
		if(g_iCvarColor_boomerstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_boomerstone);
		}
	}	
	if(StrEqual(classname, "hunter", true)) //猎人
	{
		if(g_iCvarColor_hunterstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_hunterstone);
		}
	}	
	if(StrEqual(classname, "spitter", true)) //口水
	{
		if(g_iCvarColor_spitterstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_spitterstone);
		}
	}	
	if(StrEqual(classname, "jockey", true)) //猴子
	{
		if(g_iCvarColor_jockeystone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_jockeystone);
		}
	}	
	if(StrEqual(classname, "charger", true)) //牛牛
	{
		if(g_iCvarColor_chargerstone > 0) //enable glow
		{
			SetEntProp(entity, Prop_Send, "m_iGlowType", 2); //2 = 仅当对象可见时才可见的亮度，3 = 透过对象可见的亮度。
			SetEntProp(entity, Prop_Send, "m_nGlowRange", 0); //设置发光范围，0=很远都能看到
			SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarColor_chargerstone);
		}
	}		
}